package com.swpu.cbg.cnshop.activity;

import android.app.Application;
import android.content.Context;
import android.content.Intent;

import com.facebook.drawee.backends.pipeline.Fresco;
import com.swpu.cbg.cnshop.bean.User;
import com.swpu.cbg.cnshop.utils.UserLocalData;

/**
 * Created by chenboge on 16/2/18.
 */
public class MyApplication extends Application {

    private User user;

    private static MyApplication mApplication;

    @Override
    public void onCreate() {
        super.onCreate();
        Fresco.initialize(getApplicationContext());
        mApplication = this;
        initUser();
    }

    private void initUser() {
        this.user = UserLocalData.getUser(this);
    }


    public static MyApplication getInstanse() {
        return mApplication;
    }

    public User getUser() {
        return user;
    }

    public void clearUser() {
        this.user=null;
        UserLocalData.clearUser(this);
        UserLocalData.clearToken(this);
    }

    public void putUser(User user, String token) {
        this.user = user;
        UserLocalData.putUser(this, user);
        UserLocalData.putToken(this, token);
    }

    public String getToken() {
        return UserLocalData.getToken(this);
    }

    public void clearToken() {

    }

    public String putToken(String token) {
        return "";
    }


    private Intent intent;
    public void putIntent(Intent intent) {
        this.intent = intent;
    }

    public Intent getIntent() {
        return intent;
    }

    public void jumpToIntent(Context context){
        context.startActivity(intent);
        this.intent = null;
    }
}
